package r4.pierwszy.raz;

import java.text.DateFormat;
import java.text.NumberFormat;
import java.util.Date;
import java.util.GregorianCalendar;

public class Pracownik {

	public static void increaseSalary(Pracownik pracownik) {
		pracownik.setSalary(pracownik.getSalary() * 2);
	}

	private static int assignID() {
		nextId++;
		return nextId;
	}

	private final Date hireDate;
	private double salary;
	private double bonus;
	private String name;
	private final int id;
	private static int nextId;
	
	static {
		nextId = 0;
	}

	private NumberFormat currencyFormatter = NumberFormat.getCurrencyInstance();

	private NumberFormat percentFormatter = NumberFormat.getPercentInstance();

	public Pracownik(String name, int day, int month, int year, double salary,
			double bonus) {
		this.name = name;
		this.salary = salary;
		this.bonus = bonus / 100;
		this.hireDate = new GregorianCalendar(year, month - 1, day).getTime();
		this.id = Pracownik.assignID();
	}

	public void doubleSalary() {
		this.salary *= 2;
	}

	public final double getBonus() {
		return bonus;
	}

	public final Date getHireDate() {
		return hireDate;
	}

	public final String getName() {
		return name;
	}

	public final double getSalary() {
		return salary;
	}

	public final void setSalary(double salary) {
		this.salary = salary;
	}

	@Override
	public String toString() {
		String s = new StringBuilder("[" + id + "] " + name + ", zatrudniony "
				+ DateFormat.getDateInstance().format(this.hireDate)).append(
				", zarabia: " + currencyFormatter.format(this.salary)
						+ ", premia: " + percentFormatter.format(this.bonus))
				.toString();
		return s;
	}
}
